<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php
	include "../../connect.php";
	if(isset($_REQUEST["timdondatsan"]))
	{
	$maphieu=isset($_REQUEST["maphieu"])?$_REQUEST["maphieu"]:'';
	$masan=isset($_REQUEST["masan"])?$_REQUEST["masan"]:'';
	$tenthanhvien=isset($_REQUEST["tenthanhvien"])?$_REQUEST["tenthanhvien"]:'';
	$tungay=isset($_REQUEST["tungay"])?$_REQUEST["tungay"]:'';
	$denngay=isset($_REQUEST["denngay"])?$_REQUEST["denngay"]:'';
	$wh="";
	if($maphieu!='') 
		$wh.=" and PhieuDatSanNo='$maphieu'";
	if($masan!='')
		$wh.=" and SanID='$masan'";
	if($tenthanhvien!='')
		$wh.=" and HoTen='$tenthanhvien'";
	if($tungay!='' and $denngay=='')
		$wh.=" and NgayLap BETWEEN '$tungay' and CURDATE()";
	else if ($tungay=='' and $denngay!='')
		$wh.=" and NgayLap BETWEEN CURDATE() and '$denngay'";
	else if ($tungay!='' and $denngay!='')
		$wh.=" and NgayLap BETWEEN '$tungay' and '$denngay'";		
$strSQL = "select * from phieudatsan p INNER JOIN thanhvien t on p.ThanhVienID=t.ThanhVienID
			where 1".$wh." and TrangThai<>3";
//echo $strSQL;
$result = mysql_query($strSQL);
$n=mysql_num_rows($result);
if($n>0)
{
?>
			<table border="0" width="100%" cellpadding="0" cellspacing="0" height="50px">
				<tr>
					<th class="table-header-repeat line-left"  width="100px"><a href="">STT</a>	</th>
					<th class="table-header-repeat line-left" width="210px"><a href="">Mã Phiếu</a></th>
					<th class="table-header-repeat line-left"  width="210px"><a href="">Ngày Lập</a></th>
					<th class="table-header-repeat line-left"  width="210px"><a href="">Tên Thành Viên</a></th>
                    <th class="table-header-repeat line-left" width="180px"><a href="">Mã Sân</a></th>
                    <th class="table-header-repeat line-left"><a href="">Tiền Thuê</a></th>
				</tr>
                </table>
  <div style="max-height:300px; overflow:auto;">
  <table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
 <?php
 $i=$start;$tongtien=0;
while($r3 = mysql_fetch_assoc($result))
{
	$i++;
	$phieudatsanid=$r3["PhieuDatSanID"];
	$phieudatsanno=$r3["PhieuDatSanNo"];
			$ngaylap=$r3["NgayLap"];
			$hoten=$r3["HoTen"];
			$sanid=$r3["SanID"];
			$thanhtien=$r3["ThanhTien"];
			$tongtien+=$thanhtien;
			$trangthai=$r3["TrangThai"];
			if($trangthai==1)
				echo "<tr style=\"background:#FFC;cursor:pointer\" ondblclick=\"chitietdondatsan('$phieudatsanid');\">";
			else if($trangthai==2)
				echo "<tr style=\"background:#A893FF;cursor:pointer\" ondblclick=\"chitietdondatsan('$phieudatsanid');\">";
			else if($trangthai==3)
				echo "<tr style=\"background:red;cursor:pointer\" >";
			else
				echo "<tr style=\"background:white;cursor:pointer\" ondblclick=\"chitietdondatsan('$phieudatsanid');\">";
			?>
             <!--  -->
				
					<td width="90px"><?php echo "$i"; ?></td>
					<td width="200px"><?php echo "$phieudatsanno"; ?></td>
					<td width="200px"><?php echo "$ngaylap"; ?></td>
					<td width="200px"><?php echo "$hoten"; ?></td>
					<td width="170px"><?php echo "$sanid"; ?></td>
                    <td ><?php echo "$thanhtien"; ?></td>
				</tr>
   <?php 
   			}
    ?> 
    </table>
   </div>
   <table id="tongtien">
  	<tr>
    <td colspan="5">Tổng Tiền :</td>
    <td><?php echo "$tongtien"; ?> VNĐ</td>
    </tr>
  </table>
 <?php
}
else
	{
		echo "<script>alert('Không tìm thấy kết quả nào phù hợp!');</script>";
	}
	}
?>